<?php
	if(!isset($_SESSION['member_is_admin']) || $_SESSION['member_is_admin'] == ''){
		header("Location: index.php");
	}
	
	//--
	$xtpl_main->assign ( "page_title", "Category" );
	
	//-- Delete a category
	if(isset($_GET['del_cate_id'])){
		mysql_query("UPDATE category SET cate_status = '2' WHERE cate_id = '".$_GET['del_cate_id']."'");
		header("Location: ?mod=admin&act=category");
	}
	
	//-- List all category
	$resultListAdminCategory = mysql_query("SELECT * FROM category WHERE cate_status <> '2'");
	$iCountAdminCategory = 0;
	while($rowListAdminCategory = mysql_fetch_array($resultListAdminCategory)){
		$iCountAdminCategory++;
		$rowListAdminCategory['iCountAdminCategory'] = $iCountAdminCategory;
		
		//--
		if($rowListAdminCategory['cate_status'] == '1'){
			$rowListAdminCategory['cate_status'] = 'active';
		}else{
			$rowListAdminCategory['cate_status'] = 'inactive';
		}
		
		//-- Count movie
		$rsCountMovies = mysql_query("SELECT movie_id FROM movie WHERE cate_id = '".$rowListAdminCategory['cate_id']."'");
		$rowListAdminCategory['movie_count'] = mysql_num_rows($rsCountMovies);
		
		//-- Link edit
		$rowListAdminCategory['cate_edit_link'] = '?mod=admin&act=category-task&cate_id='.$rowListAdminCategory['cate_id'];
		
		//--
		$xtpl->assign('list_admin_cate', $rowListAdminCategory);
		$xtpl->parse('center.list_admin_cate');
	}
?>